package design.pattern.Lu10ChainResponsibilityPattern;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @program JavaBase
 * @description: 责任链模式
 * @author: zhanglu
 * @create: 2020-04-07 22:40:00
 */
public class Lu10NoChainResponsibilityPattern {

    public static void main(String[] args) {

        Random random = new Random();

        List<IWomen> womenList = new ArrayList<>();

        for (int i = 0; i < 3; i++) {
            womenList.add(new Women(random.nextInt(4), "去逛街"));
        }

        IHandler father = new Father();
        IHandler husband = new Husband();
        IHandler son = new Son();

        for (IWomen women : womenList) {
            if(women.getType() ==1){ //未结婚少女，请示父亲
                System.out.println("\n--------女儿向父亲请示-------");
                father.handleMessage(women);
            }else if(women.getType() ==2){ //已婚少妇，请示丈夫
                System.out.println("\n--------妻子向丈夫请示-------");
                husband.handleMessage(women);
            }else if(women.getType() == 3){ //母亲请示儿子
                System.out.println("\n--------母亲向儿子请示-------");
                son.handleMessage(women);
            }else{ //暂时什么也不做

            }
        }

    }

}

interface IWomen{

    int getType();

    String getRequest();

}

class Women implements IWomen{

    private int type = 0;

    private String request = "";

    public Women(int type, String request){
        this.type = type;
        this.request = request;
    }

    @Override
    public int getType() {
        return type;
    }

    @Override
    public String getRequest() {
        return this.request;
    }
}

interface IHandler{
    void handleMessage(IWomen women);
}

class Father implements IHandler{

    @Override
    public void handleMessage(IWomen women) {
        System.out.println("女儿的请示是：" + women.getRequest());
        System.out.println("父亲的回答是：同意");
    }
}

class Husband implements IHandler{

    @Override
    public void handleMessage(IWomen women) {
        System.out.println("妻子的请示是：" + women.getRequest());
        System.out.println("丈夫的回答是：同意");
    }
}

class Son implements IHandler{

    @Override
    public void handleMessage(IWomen women) {
        System.out.println("母亲的请示是：" + women.getRequest());
        System.out.println("儿子的回答是：同意");
    }
}



